feat: Add finish_reason field to StreamingChunk#9536
Conversation
Pull Request Test Coverage Report for Build 15871955598Warning: This coverage report may be inaccurate.This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.
Details
💛 - Coveralls |
|
@sjrl please review and make sure that PR and migration plan make sense to you 🙏 |
|
The issue corresponding to this PR is already in the 2.15.0 milestone. That's the reason why I removed the PR from the milestone again. It's still planned to be part of the release. |
|
Hey @vblagoje thanks for your work on this! I'll do a more in-depth review today but first I had a few comments and questions.
|
|
@vblagoje could we also drop the migration and deprecation info in the PR description? |
|
Thank you @sjrl - much appreciate taking care of this one through the finish line! |
Why:
Introduces a dedicated
finish_reasonfield toStreamingChunkclass to improve type safety and provide better developer experience when handling streaming finish reasons. This enhancement adds structured access to finish reasons while maintaining full backward compatibility with the existing meta-based approach.finish_reasonfield toStreamingChunk#9471What:
finish_reason: Optional[FinishReason]field toStreamingChunkclass with strict typingFinishReasonLiteral type with standard values ("stop", "length", "tool_calls", "content_filter", "tool_call_results")How can it be used:
Both approaches currently work, but we recommend using the dedicated
StreamingChunkfield:How did you test it:
Notes for the reviewer:
Dual Support Strategy: This implementation provides current support for both access patterns:
chunk.finish_reasonprovides type safety, better IDE support, and future compatibilitychunk.meta["finish_reason"]works for existing code but will likely be removed in future versions